/*
 * @brief:
 *
 * @author: dariaye@tencent.com
 * @date: 2012-7-16
 * @version: 1.0
 * @changes:
 *    <author>        <time>        <version >        <desc>
 *     dariaye             2012-7-16              1.0                 Create
 */

#include <assert.h>
#include <string.h>
#include "log_util.h"
#include <os/fs.h>
#include <port/dirname.h>

char kInfoFileName[PATH_MAX] = "../log/plsa_training_info";
char kErrorFileName[PATH_MAX] = "../log/plsa_training_error";

LOG_DEFINE(plsa_log_info);
LOG_DEFINE(plsa_log_error);

void SetPLSALogFileName(const char * info_log_file_name,
        const char * error_log_filename, BASE::Log::kLogLevel log_level,
        BASE::Log::kLogOutPut log_output)
{
    if (!info_log_file_name || !error_log_filename)
    {
        return;
    }

    strncpy(kInfoFileName, info_log_file_name, PATH_MAX);
    strncpy(kErrorFileName, error_log_filename, PATH_MAX);

    char buffer[512];
    strncpy(buffer, info_log_file_name, 512);
    char * pathname = dirname(buffer);
    if (pathname && IsDir(pathname) < 0 && MakeDirRecursive(pathname) < 0)
        return;

    strncpy(buffer, error_log_filename, 512);
    pathname = dirname(buffer);
    if (pathname && IsDir(pathname) < 0 && MakeDirRecursive(pathname) < 0)
        return;

    LOG_INIT_v2(plsa_log_info, kInfoFileName, log_level, log_output);
    LOG_INIT_v2(plsa_log_error, kErrorFileName, log_level, log_output);
}

void CloseLog()
{
    LOG_CLOSE_v2(plsa_log_info);
    LOG_CLOSE_v2(plsa_log_error);
}

